<template>
  <div id="app">
    <header class="header">
      <span class="icon-container">
        <i class="el-icon-message-solid"></i>
      </span>
      <span class="scrolling-text">欢迎来到种花吧交流论坛，请友善分享经验，严禁交流违法违规内容，遵纪守法，文明你我他</span>
    </header>
    <main class="main">
      <section class="item" v-for="(form, index) in forms" :key="form.id || index">
        <div class="user-info">
          <div class="avatar-wrapper">
            <div class="circle">
              <img :src="form.user_avatar"/>
            </div>
            <div class="user-details">
              <span class="nickname">{{ form.user_nickname }}</span>
              <span class="separator">|</span>
              <span class="time">{{ form.createdAt }}</span>
            </div>
          </div>
        </div>

        <div class="content" @click="clickpost(form.post_id)">
          <div class="post-media">
            <img v-if="form.type" :src="getFirstImage(form.type)" alt="Post Image" />
            <div v-else class="default-image">
              <span class="default-text">种</span>
              <span class="default-text">花</span>
              <span class="default-text">吧</span>
            </div>
          </div>
          <div class="post-details">
            <h1 class="post-title">{{ form.title }}</h1>
            <p class="post-body">{{ form.mainboby }}</p>
            <div class="post-stats">
              <div class="left-stats">
                <div class="stat-item">
                  <i class="el-icon-view"></i>
                  <span>{{ form.views }}</span>
                </div>
                <div class="stat-item">
                  <i class="el-icon-chat-dot-square"></i>
                  <span>{{ form.replies }}</span>
                </div>
                <div class="stat-item">
                  <i class="el-icon-share"></i>
                  <span>分享</span>
                </div>
              </div>
              <el-tag :type="getCategoryType(form.category)">{{ form.category }}</el-tag>
            </div>
          </div>
        </div>
      </section>
    </main>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      forms: {},
    };
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.request.get("/originalposts/list").then(res => {
        this.forms = res.data
        console.log(res.data);
      })
    },
    getFirstImage(type) {
      if (!type) {
        return require('@/assets/images/juan.jpg');
      }
      const images = type.split(',');
      return images[0] || require('@/assets/images/juan.jpg');
    },
    clickpost(postId) {
      this.$router.push(`/detail/${postId}`);
      console.log("跳转路由");
    },
    getCategoryType(category) {
      const types = {
        'flower_share': 'success',
        'care_tips': 'warning',
        'flower_story': 'info',
        'purchase_advice': 'danger'
      };
      return types[category] || 'info';
    }
  }
};
</script>

<style scoped>
#app {
  min-height: 100vh;
  background-color: #f5f7fa;
  padding: 20px;
  box-sizing: border-box;
}

.header {
  background-color: white;
  padding: 15px 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  overflow: hidden;
  position: relative;
}

.icon-container {
  color: #ff4757;
  margin-right: 15px;
  flex-shrink: 0;
  font-size: 20px;
}

.scrolling-text {
  color: #606266;
  font-size: 14px;
  animation: scrollText 25s linear infinite;
}

@keyframes scrollText {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

.main {
  display: grid;
  gap: 15px;
}

.item {
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
}

.item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px 0 rgba(0,0,0,0.1);
}

.avatar-wrapper {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #f0f2f5;
}

.circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.circle img:hover {
  transform: scale(1.1);
}

.user-details {
  margin-left: 12px;
}

.nickname {
  font-weight: 600;
  color: #303133;
}

.separator {
  margin: 0 8px;
  color: #909399;
}

.time {
  color: #909399;
  font-size: 13px;
}

.content {
  display: flex;
  gap: 20px;
  min-height: 130px;
}

.post-media {
  width: 280px;
  height: 180px;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #1e90ff, #4169e1);
  position: relative;
}

.post-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.post-media img:hover {
  transform: scale(1.05);
}

.post-details {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.post-title {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 12px 0;
}

.post-body {
  color: #606266;
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 auto 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #f0f2f5;
}

.left-stats {
  display: flex;
  gap: 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #909399;
  font-size: 13px;
  cursor: pointer;
  transition: color 0.3s ease;
}

.stat-item:hover {
  color: #409EFF;
}

.stat-item i {
  font-size: 16px;
}

.el-tag {
  border-radius: 4px;
  padding: 0 12px;
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

.default-image {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #1e90ff, #4169e1);
  position: relative;
  overflow: hidden;
}

.default-image::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent 0%,
    rgba(255, 255, 255, 0.1) 50%,
    transparent 100%
  );
  animation: shine 3s infinite linear;
}

.default-text {
  font-size: 36px;
  font-weight: bold;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  font-family: "楷体", "STKaiti", serif;
  animation: float 3s infinite ease-in-out;
}

.default-text:nth-child(2) {
  animation-delay: 0.2s;
}

.default-text:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes shine {
  0% {
    transform: translateX(-100%) translateY(-100%) rotate(45deg);
  }
  100% {
    transform: translateX(100%) translateY(100%) rotate(45deg);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}
</style>